package com.gjp.globalization.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

/**
 * Created by Gjp on 2018-11-20.
 * 参考地址：https://blog.csdn.net/lwphk/article/details/41822447
 */
@Configuration
public class MessageSourceConfig {

    @Bean
    public SessionLocaleResolver localeResolver(){
        return new SessionLocaleResolver();
    }

//    @Bean
//    public CookieLocaleResolver localeResolver(){
//        CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
//        cookieLocaleResolver.setCookieName("locale");
//        cookieLocaleResolver.setCookieMaxAge(604800);
//        cookieLocaleResolver.setDefaultLocale(Locale.CHINESE);
//        return cookieLocaleResolver;
//    }

    @Bean
    public ResourceBundleMessageSource messageSource(){
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        //如果没有找到国际化key值 默认输出key
        messageSource.setUseCodeAsDefaultMessage(true);
        //src/messages
        messageSource.setBasenames("messages/messages");
        return messageSource;
    }
}
